#!/bin/bash

if [ $# -lt 1 -o $# -gt 2 ];then
    echo "Usage: $0 name [tag]"
    exit 1
fi

src=nginx/src
core=$src/core/nginx.h
filter=$src/http/ngx_http_header_filter_module.c
special=$src/http/ngx_http_special_response.c

NGINXVERSION='1.11.2'
NGINXVER='\"openresty\/\" NGINX_VERSION \"\.5\"'
ngx_http_server_string='Server: openresty'
ngx_http_error_tail='<hr><center>openresty<\/center>'

name=$1
if [ -z "$2" ];then
    ver="latest"
else
    ver=$2
fi

sed -i "s/$NGINXVERSION/$ver/" $core
sed -i "s/$NGINXVER/\"$name\/\" NGINX_VERSION/" $core
sed -i "s/$ngx_http_server_string/Server: $name/" $filter
sed -i "s/$ngx_http_error_tail/<hr><center>$name<\/center>/" $special
